<?php

/**
 * Search Log model
 */
class LogModel extends DocModel
{
	private $_errDb = false;

	public function init()
	{
		parent::init();
		$xs = $this->getXS();
		$xs->setScheme(XSFieldScheme::logger());
		try {
			$xs->index->setDb(XSSearch::LOG_DB);
			$xs->search->setDb(XSSearch::LOG_DB);
		} catch (XSException $e) {
			if ($e->getCode() !== CMD_ERR_XAPIAN) {
				throw $e;
			}
			$this->_errDb = true;
		}
	}

	public function getPrimaryKey()
	{
		return $this->body;
	}

	public function findAll($query)
	{
		return $this->_errDb ? array() : parent::findAll($query);
	}

	public function typeOptions()
	{
		return array(
			'currnum' => '本周',
			'lastnum' => '上周',
			'total' => '总计',
		);
	}
}
